home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Archive Magazine CD 1995
/
Archive Magazine CD 1995.iso
/
discs
/
shareware
/
share_41
/
assembler
/
examples
/
sort
< prev
next >
Wrap
Text File
|
1991-05-17
|
1KB
|
60 lines
; NAME sort
; PURPOSE sorts the characters in text1
; DESIGN
; count nunber of characters
; repeat
; done <- true
; for i = 0 to number of characters
; if character[i+1] > character[i]
; then
; swap character[i+1] with character[i]
; done <- false
; end if
; end for
; until done
; sorts the letters in a string
; based on bubble sort
; first count the number of characters
mov r0, #0
sub r0, r0, #1
mov r6, #0
.count_loop
add r0, r0, #1
ldrb r6, [r4, r0]
cmp r6, #31
bpl count_loop
; now sort them
mov r6, #0
mov r7, #0
mov r1, #1
mov r2, #0
add r5, r4, #1
sub r0, r0, #1
.repeat
mov r1, #1
mov r2, #0
.for
ldrb r6, [r4, r2]
ldrb r7, [r5, r2]
cmp r7, r6
bpl no_swap
mov r8, r6
mov r6, r7
mov r7, r8
strb r6, [r4, r2]
strb r7, [r5, r2]
mov r1, #0
.no_swap
add r2, r2, #1
cmp r2, r0
bmi for
cmp r1, #1
bne repeat